package com.jmpt.fangbohui.ui;

import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ListView;

import com.google.gson.Gson;
import com.jmpt.fangbohui.Constants;
import com.jmpt.fangbohui.R;
import com.jmpt.fangbohui.adapter.BrokerPersonNetSotreEsHouse1ListAdapter;
import com.jmpt.fangbohui.bean.BrokerPersonNetSotreEsHouseBean1;
import com.jmpt.fangbohui.bean.BrokerPersonNetSotreEsHouseBean1.Retval;
import com.jmpt.fangbohui.ui.base.BaseHeadActivity;
import com.jmpt.fangbohui.utils.DebugLog;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;

public class BrokerPersonNetStoreEsHouse2ListActivity extends BaseHeadActivity{

	private String uid = "2289";
	public static final int SUCCESS = 505;
	public static final int FAILED = 404;
	
	private Handler handler = new Handler(){
		public void handleMessage(android.os.Message msg) {
			hideLoading();
			switch(msg.what){
			case SUCCESS:
				String result = (String) msg.obj;
				parser(result);
				break;
			case FAILED:
				
				break;
				
			}
		};
	};
	private ListView lv_broker_person_net_store_eshouse_1;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_eshouse1);
		getExtra();
		initView();
	}

	protected void parser(String result) {
		DebugLog.i(result);
		Gson gson = new Gson();
		BrokerPersonNetSotreEsHouseBean1 bean1 = gson.fromJson(result, BrokerPersonNetSotreEsHouseBean1.class);
		List<Retval> retval = bean1.retval;
		BrokerPersonNetSotreEsHouse1ListAdapter mAdapter = new BrokerPersonNetSotreEsHouse1ListAdapter(this,retval);
		lv_broker_person_net_store_eshouse_1.setAdapter(mAdapter);
	}

	private void getExtra() {
		Intent intent = getIntent();
		uid = intent.getStringExtra("uid");
		getDataForNet();
	}

	private void getDataForNet() {
		showLoading();
		HttpUtils utils = new HttpUtils();
		utils.send(HttpMethod.POST, Constants.URL.BROKERPERSONNETSTOREHOMEPAGELIST+"?H_SaleOrRent=2&uid="+uid, new RequestCallBack<String>() {
			@Override
			public void onFailure(HttpException arg0, String arg1) {
				Message obtain = Message.obtain();
				obtain.what = FAILED;
				handler.sendMessage(obtain);
			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				Message obtain = Message.obtain();
				obtain.what = SUCCESS;
				obtain.obj = arg0.result;
				handler.sendMessage(obtain);
			}
		});
	}

	private void initView() {
		setTitle("租房列表");
		showBackButton(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		lv_broker_person_net_store_eshouse_1 = (ListView) findViewById(R.id.lv_broker_person_net_store_eshouse_1);
	}
}
